package cn.jinhe.doc.view.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.jinhe.doc.base.BaseAction;
import cn.jinhe.doc.domain.Repository;
import cn.jinhe.doc.domain.Role;
import cn.jinhe.doc.util.QueryHelper;
@Controller
@Scope("prototype")
public class RepositoryManagerAction extends BaseAction<Repository>{
	 public String list() throws Exception{
//		List<Repository> repositoryList=repositoryService.findAll();
//		 ActionContext.getContext().put("repositoryList", repositoryList);
		new QueryHelper(Repository.class, "r").addOrderProperty(true, "r.positions", true).preparePageBean(repositoryService, pageNum, pageSize);

		 return "list";
		 }
		 
		 /*
		  * 删除
		  */
		 public String delete() throws Exception{
			 repositoryService.delete(model.getId());
			 return "toList";
		 }
		 
		 /*
		  * 添加
		  */
		 public String add() throws Exception{
			 repositoryService.save(model);
			 return "toList";
		 }
		 
		 /*
		  * 添加页面
		  */
		 public String addUI() throws Exception{
		  return "saveUI";
		 }
		 /*
		  * 修改页面
		  */
		 public String editUI() throws Exception{
		 
				Repository repository = repositoryService.getById(model.getId());
				ActionContext.getContext().getValueStack().push(repository);
				return "saveUI";
		 }
		 /*
		  * 修改
		  */
		 public String edit() throws Exception{
			 Repository repository=repositoryService.getById(model.getId());
			 repository.setDescription(model.getDescription());
			 repository.setName(model.getName());
			 repositoryService.update(repository);
			 return "toList";
		 }
		 
		 /*
		  * 上移
		  */
		 public String moveUp() throws Exception{
			 repositoryService.moveUp(model.getId());
			 return "toList";
		 }
		 
		 /*
		  * 下移
		  */
		 public String moveDown() throws Exception{
			 repositoryService.moveDown(model.getId());
			 return "toList";
		 }
	
}
